In [1]:
!pip install plotly
Looking in indexes: https://pypi.org/simple, https://pypi.ngc.nvidia.com
Requirement already satisfied: plotly in c:\users\laksh\anaconda3_new\lib\site-packages (5.9.0)
Requirement already satisfied: tenacity>=6.2.0 in c:\users\laksh\anaconda3_new\lib\site-packages (from plotly) (8.0.1)
In [2]:
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import sklearn as sk
import plotly.express as px
import plotly.graph_objects as go
In [3]:
pd.set_option('display.max_columns',None)
In [4]:
df = pd.read_csv("swiggyData.csv")
df.sample(5)
Out[4]:
ID Area City Restaurant Price Avg ratings Total ratings Food type Address Delivery time
3439 332172 New Malakpet Hyderabad Grill Station 200.0 3.9 20 Indian Kothapet & Dilsukhnagar 44
862 37747 Kothrud Pune Community Cafe 300.0 3.8 20 Cafe Kothrud 59
828 36461 Chembur Mumbai Freshmenu 250.0 4.1 1000 Chinese Continental Italian Mediterranean ... Opp Kanta Apartment 48
7462 121189 Ambawadi Ahmedabad Jalaram Parotta House 200.0 3.9 100 North Indian,Gujarati Bopal 37
6772 37306 Kothrud Pune Waari Book Cafe 200.0 3.9 100 Desserts Kothrud 52
In [5]:
df = df.drop(['ID'],axis=1)
df.sample(5)
Out[5]:
Area City Restaurant Price Avg ratings Total ratings Food type Address Delivery time
5222 Rajouri Garden Extension Delhi Louis Burger 600.0 4.2 500 American,Fast Food Rajouri Garden Extension 74
7659 Santacruz East Mumbai Srirang Foods 300.0 4.7 20 Indian 7Th Road Tps Iii Santacruz 52
376 T. Nagar Chennai Moonlight Takeaway & Delivery 250.0 4.0 1000 Indian,Chinese,Tandoor T. Nagar 66
643 Mundhwa Pune Shisha Jazz Cafe 600.0 2.9 80 North Indian,Persian Koregaon Park 61
7077 Navrangpura Ahmedabad Anand Ankurwala 300.0 4.2 50 Fast Food,Snacks Navrangpura 34
In [6]:
df.shape
Out[6]:
(8680, 9)
In [7]:
df.isnull().sum()
Out[7]:
Area             0
City             0
Restaurant       0
Price            0
Avg ratings      0
Total ratings    0
Food type        0
Address          0
Delivery time    0
dtype: int64

Data Analysis¶

In [8]:
cityGrouped = df.groupby('City')
averageRating = cityGrouped['Avg ratings'].mean()
fig = go.Figure(data=go.Scatter(x=averageRating.index, y=averageRating.values, mode='markers+lines'))
fig.update_layout(title='Average Rating', xaxis_title='City', yaxis_title='Average Rating')
fig.show()
In [9]:
cityGrouped = df.groupby('City')
averageDelivery = cityGrouped['Delivery time'].mean()
fig = px.line(averageDelivery, x=averageDelivery.index, y=averageDelivery.values, title='Average Delivery Time')
fig.update_traces(mode='markers+lines')
fig.update_layout(xaxis_title='City', yaxis_title='Average Delivery Time')
fig.show()
In [10]:
cityGrouped = df.groupby('City')
averagePrice = cityGrouped['Price'].mean()
fig = go.Figure(data=go.Scatter(x=averagePrice.index, y=averagePrice.values, mode='markers+lines'))
fig.update_layout(title='Average Price', xaxis_title='City', yaxis_title='Average Price')
fig.show()
In [11]:
df.sample(5)
Out[11]:
Area City Restaurant Price Avg ratings Total ratings Food type Address Delivery time
7599 Ambawadi Ahmedabad Meal Box Ambawadi 200.0 3.0 20 North Indian,Chinese Navrangpura 38
2496 Piplod Surat Starbucks Coffee 400.0 4.5 50 Beverages,Bakery Dumas Road 53
150 Bidhannagar Kolkata The Darjeeling 500.0 4.0 100 Chinese,Nepalese,Tibetan Near City Centre 1 73
928 Mylapore Chennai Classic Shawarma And Grill 250.0 4.1 20 Arabian,Fast Food Mylapore Kutcheri Road 58
541 Choolaimedu Chennai Naga Reju Fast Food 300.0 4.3 500 Naga,Chinese,Continental Arumbakkam 52
In [12]:
df.sample(10)
Out[12]:
Area City Restaurant Price Avg ratings Total ratings Food type Address Delivery time
1609 Kurla Mumbai Urban Jalsa 400.0 4.3 100 Fast Food,Continental,Chinese,Special Discount... Kurla 33
523 Balavinayagar Nagar Chennai Hotel Arafa 400.0 4.0 100 South Indian,Biryani,Kebabs Arumbakkam 58
3128 Piplod Surat Oven & Grill 250.0 3.7 100 Pizzas,Combo,American,Desserts,Beverages,Snacks Udhna 60
142 Bidhannagar Kolkata First Innings - The Stadel Hotel 800.0 4.5 20 North Indian,Chinese,Continental Sector 3 69
5087 Rohini Delhi Chotiwala -The Mouth Watering Food 300.0 2.9 80 North Indian,Biryani Rohini 61
2420 Rohini Delhi La Pino'Z Pizza 500.0 3.9 1000 Pizzas Dc Chowk 45
3073 Narayan Peth Pune Barbeque Nation 600.0 4.0 100 North Indian,Mughlai,Seafood,Biryani,Desserts,... Deccan Heights Fourth Floor 45
1206 Ashok Nagar Bangalore Sweet Chariot 50.0 2.9 80 Desserts Brigade Road 36
7672 Adajan Surat Trishiv Chinese Corner 200.0 4.1 500 Chinese,Fast Food,Street Food,Pan-Asian,Asian Anand Mahal Road 44
6912 Ashok Nagar Bangalore Mtr 300.0 4.4 1000 South Indian Central Bangalore 28
In [13]:
food_types = df['Food type'].str.split(',', expand=True)
food_types
Out[13]:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
0 Biryani Chinese North Indian South Indian None None None None None None None None None None None None None None None None None None None
1 Mughlai Lucknowi None None None None None None None None None None None None None None None None None None None None None
2 Chinese None None None None None None None None None None None None None None None None None None None None None None
3 North Indian Punjabi Tandoor Chinese None None None None None None None None None None None None None None None None None None None
4 Rajasthani Gujarati North Indian Snacks Desserts Beverages Thalis Chaat None None None None None None None None None None None None None None None
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
8675 Pizzas None None None None None None None None None None None None None None None None None None None None None None
8676 South Indian None None None None None None None None None None None None None None None None None None None None None None
8677 Chinese Snacks Tandoor None None None None None None None None None None None None None None None None None None None None
8678 North Indian Indian Snacks None None None None None None None None None None None None None None None None None None None None
8679 Chaat Snacks Chinese None None None None None None None None None None None None None None None None None None None None

8680 rows × 23 columns

In [14]:
percentage_filled = food_types.count() / food_types.shape[0] * 100
In [15]:
foodtype1 = food_types[0]
foodtype2 = food_types[1]
df['Major food type'] = foodtype1
df = df.drop(['Food type'],axis=1)
df.sample(5)
Out[15]:
Area City Restaurant Price Avg ratings Total ratings Address Delivery time Major food type
4657 Burrabazar Kolkata Where To Go 600.0 2.9 80 Burrabazar 49 Tandoor
1911 Sector 8 Rohini Delhi Royal Burger By Vhc 150.0 2.9 80 Nsp 47 Beverages
8436 Alwarpet Chennai Jallikattu Biriyani 400.0 2.9 80 Alwarpet 72 Biryani
5956 Ashok Nagar Hyderabad C Kitchen 250.0 2.9 80 Ashok Nagar 40 Chinese
5099 Rohini Delhi Bemisal Dharmender Hotel 300.0 2.9 80 Rohini 55 North Indian
In [16]:
count = df['City'].value_counts().nlargest(10)
df_filtered = df[df['City'].isin(count.index)]
top_food_types = df_filtered['Major food type'].value_counts().nlargest(10).index
top_food_types = top_food_types[top_food_types != 'Indian']  # Remove 'Indian' from major food types
df_filtered = df_filtered[df_filtered['Major food type'].isin(top_food_types)]
grouped = df_filtered.groupby(['City', 'Major food type']).size().unstack()
grouped_percentage = grouped.div(grouped.sum(axis=1), axis=0) * 100 

fig = px.bar(grouped_percentage, barmode='stack', title='Percentage of Top 10 Major Food Types in Top 10 Cities')
fig.update_layout(xaxis_title='City', yaxis_title='Percentage', showlegend=True)

fig.show()
In [17]:
fig = px.bar(df.groupby('City')['Area'].nunique(), title='Number of Areas Based on City')
fig.update_layout(xaxis_title='City', yaxis_title='Number of Areas')

fig.show()
In [18]:
df['Total ratings'] = df['Avg ratings'] * df['Total ratings']
top_restaurants = df.nlargest(10, 'Total ratings')  # Select top 10 restaurants based on total ratings

fig = px.bar(top_restaurants, x='Restaurant', y='Total ratings', color='Major food type',
             title='Top Restaurants with Major Food Types')
fig.update_layout(xaxis_title='Restaurant', yaxis_title='Total Ratings', showlegend=True)

# Add city information as a hover text
fig.update_traces(hovertemplate='<b>%{x}</b><br>Total Ratings: %{y}<br>City: %{customdata[0]}',
                  customdata=[top_restaurants['City']])

fig.show()
In [ ]: